package tr.edu.ege.kipler.satisfiability.syntactical;

import java.util.LinkedHashSet;
import java.util.Set;

import tr.edu.ege.kipler.syntax.BinaryBooleanExpression;
import tr.edu.ege.kipler.syntax.ModalExpression;
import tr.edu.ege.kipler.syntax.WorldElementVisitor;
import tr.edu.ege.kipler.syntax.atomicformula.ConceptAssertion;
import tr.edu.ege.kipler.syntax.atomicformula.ConceptDefinition;
import tr.edu.ege.kipler.syntax.atomicformula.ObjectRoleAssertion;
import tr.edu.ege.kipler.syntax.atomicformula.RoleAssertion;
import tr.edu.ege.kipler.syntax.atomicformula.RoleInclusion;
import tr.edu.ege.kipler.syntax.atomicformula.SameIndividualAssertion;

/**
 * 
 * @author İnanç Seylan
 *
 */
public class IndividualCollectionFromFormulaVisitor implements
		WorldElementVisitor {
	private Set<String> oldIndividualSet = new LinkedHashSet<String>();

	public Set<String> getOldIndividualSet() {
		return oldIndividualSet;
	}

	public void visitBinaryElement(BinaryBooleanExpression be) {
		be.getLhs().accept(this);
		be.getRhs().accept(this);
	}

	public void visitConceptAssertion(ConceptAssertion ca) {
		oldIndividualSet.add(ca.getName());
		NominalCollectionFromDescriptionVisitor visitor = new NominalCollectionFromDescriptionVisitor();
		ca.getConcept().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
	}

	public void visitConceptDefinition(ConceptDefinition cd) {
		NominalCollectionFromDescriptionVisitor visitor = new NominalCollectionFromDescriptionVisitor();
		cd.getLhs().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
		visitor = new NominalCollectionFromDescriptionVisitor();
		cd.getRhs().accept(visitor);
		oldIndividualSet.addAll(visitor.getNominalSet());
	}

	public void visitModalElement(ModalExpression me) {
		me.getExpression().accept(this);
	}

	public void visitObjectRoleAssertion(ObjectRoleAssertion ra) {
		oldIndividualSet.add(ra.getOwner());
		oldIndividualSet.add(ra.getFiller());
	}

	public void visitSameIndividualAssertion(SameIndividualAssertion ia) {
		oldIndividualSet.add(ia.getLhs());
		oldIndividualSet.add(ia.getRhs());
	}

	public void visitRoleAssertion(RoleAssertion ra) {
		// nothing to do
	}

	public void visitRoleInclusion(RoleInclusion ri) {
		// nothing to do
	}

}
